How many times part appears in text - string_count("banana", "an") is 2. It only counts; it builds no string, so there is nothing to cut off.
string_count(text, part) -> int| Name | Type |
|---|---|
text | string |
part | string |
int
How many times part appears in text: string_count("banana", "an") is 2. It only counts, so it makes no new text and there is nothing to cut off.
Matches never overlap, and they are counted from left to right - the same way string_replace finds them. "aaaa" holds "aa" twice, not three times. part appearing nowhere gives 0, and so does an empty part (an empty piece of text is everywhere and nowhere at once, so GBML says 0).
string_find tells you where the first match is; string_count tells you how many there are.
var line = "ha ha ha";
var laughs = string_count(line, "ha"); // 3
var spaces = string_count(line, " "); // 2
var words = spaces + 1;
var none = string_count(line, "x"); // 0
var pairs = string_count("aaaa", "aa"); // 2, not 3: matches do not overlapMatches never overlap and are counted left to right, the same way string_replace finds them: "aaaa" holds "aa" twice, not three times. An empty part appears nowhere, so the answer is 0 (the same rule string_replace follows). 0 also means "not there at all" - string_find tells you where, string_count tells you how many.